package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.DateUtil;
import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter@Getter
@JsonIgnoreProperties(value = {"handler","hibernateLazyInitializer","fieldHandler"})
public class StrategyDetail extends BaseDomain{
    public static final int STATE_RELEASE=0;//发布
    public static final int STATE_REVIEW=1;//草稿

    private String title;//标题
    @JsonFormat(pattern ="yyyy-MM-dd" , timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date createTime;//创建事件
    @JsonFormat(pattern ="yyyy-MM-dd" , timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date releaseTime;//发布时间

    private Integer sequence;//序号

    private StrategyCatalog strategyCatalog;//攻略分类

    private String coverUrl;//封面

    private Integer state=0;//状态

    private StrategyContent strategyContent;//关联的内容

    public String getStateName() {
        if (state == STATE_RELEASE) {
            return "发布";
        } else if (state == STATE_REVIEW) {
            return "草稿";
        }
        return "";
    }

    public String getJsonString(){
        Map<String,Object> map = new HashMap<>();
        map.put("id",getId());
        map.put("title",title);
        map.put("createTime", DateUtil.formatDate(createTime));
        map.put("releaseTime", DateUtil.formatDate(releaseTime));
        if (strategyCatalog!=null){
        map.put("strategyCatalogId",strategyCatalog.getId());
        }
        map.put("sequence",sequence);
        map.put("coverUrl",coverUrl);
        if (state != null) {
            map.put("state",state);
        }
        if (strategyContent!=null){
            map.put("strategyContent",strategyContent.getContent());
        }
        return JSONUtil.toJSONString(map);
    }

}